# divide a point pattern into quadrat samples
# 
# Author: Guochun Shen
# Data:   2011-12-24
# Project:niche conservitism
# Email:  shenguochun@gmail.com
###############################################################################

quadratize=function(data.ppp,nx,ny){
	win=data.ppp$win
	xi_breaks=seq(0-1e-5,win$xrange[2]+1e-5,length.out=nx+1)
	yi_breaks=seq(0-1e-5,win$yrange[2]+1e-5,length.out=ny+1)
	xi=as.numeric(cut(data.ppp$x,breaks=xi_breaks))
	yi=as.numeric(cut(data.ppp$y,breaks=yi_breaks))
	ploti=xi+(yi-1)*nx
	marks(data.ppp)=data.frame(sp=marks(data.ppp)$sp,ploti=ploti)
	return(data.ppp)
}

